package com.atguigu.oshi.service;


import org.springframework.stereotype.Service;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;

@Service
public class CpuLoadMetricsService {

    //OSHI 提供的获取所有数据的入口
    SystemInfo si = new SystemInfo();

    public double[] getCpuLoad() {
        HardwareAbstractionLayer hardware = si.getHardware();


        CentralProcessor processor = hardware.getProcessor();

        //统计1s内的使用率，所以阻塞一秒
        double[] cpuLoad = processor.getProcessorCpuLoad(1000);

        return cpuLoad;
    }

}
